package com.wcsy.myblog.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcsy.myblog.dao.LabelMapper;
import com.wcsy.myblog.entity.Label;
import com.wcsy.myblog.entity.User;
import com.wcsy.myblog.service.ILabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class LabelServiceImpl extends ServiceImpl<LabelMapper,Label> implements ILabelService {
    @Autowired
    private LabelMapper labelMapper;
    @Autowired
    private ILabelService iLabelService;
    @Autowired
    HttpSession session;
    @Autowired
    NumServiceImpl numService;

    @Override
    public List<Label> listLabel(int userId) {
        return labelMapper.listLabel(userId);
    }

    @Override
    public boolean insertLable(Label label) throws Exception {
        Label label1 = labelMapper.LabeList(label.getLabelName());
        if (label1==null){
            Date startTime = new Date(System.currentTimeMillis());//获取当前的时间
            String format = new SimpleDateFormat("YYYY年MM月dd日HH:mm").format(startTime);
            label.setLabelTime(format);
            String getfilter = numService.getfilter(label.getLabelName());
            if (!getfilter.equals(label.getLabelName())){
                System.out.println("请勿输入敏感词汇");
                return  false;
            }
            return labelMapper.insertLable(label);
        }
        return false;
    }

    @Override
    public boolean updateLabel(String labelNamem,int labelId) {
        return labelMapper.updateLabel(labelNamem, labelId);
    }

}
